﻿using System;
using System.Windows.Forms;
using Core;

namespace UI
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void StartTranslation(object sender, EventArgs e)
        {
            Status.Text = string.Empty;

            var sourceFolder = SourceResource.Text;
            var targetFolder = TargetResource.Text;
            var sampleFile = SampleResourceFile.Text;
            var clientId = ClientId.Text;
            var clientSecret = ClientSecret.Text;

            Status.Text = "Translation started...";

            var service = new TranslatorService(clientId, clientSecret);
            var result = service.Translate(sampleFile, sourceFolder, targetFolder);

            if (result.Success)
            {
                Status.Text = "Translation completed successfully..";
            }
            else
            {
                Status.Text = "Error during translation : " + result.Message;
            }
        }

        private void SelectSourceFolderClick(object sender, EventArgs e)
        {
            FolderDialog.ShowDialog();
            SourceResource.Text = FolderDialog.SelectedPath;
        }

        private void SelectTargetClick(object sender, EventArgs e)
        {
            FolderDialog.ShowDialog();
            TargetResource.Text = FolderDialog.SelectedPath;
        }

        private void SelectSampleFileClick(object sender, EventArgs e)
        {
            SampleFileDialog.ShowDialog();
            SampleResourceFile.Text = SampleFileDialog.FileName;
        }
    }
}
